import time

# 方法1
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.switch_to import SwitchTo

wd = webdriver.Chrome(service=Service(".\chromedriver_win136.exe"), options=options)

wd.get("https://swtesting-class-demo.koyeb.app/elements/")

wd.implicitly_wait(10)


# click alert
"""
show_alert_btn = wd.find_element(By.CSS_SELECTOR, ".button-group > button:nth-child(1)")
print(show_alert_btn.get_attribute("outerHTML"))
show_alert_btn.click()
# alert=SwitchTo(wd).alert
alert = wd.switch_to.alert
print(alert.text)
time.sleep(3)
alert.accept()
time.sleep(5)
"""

# click confirm
"""
show_confirm_btn = wd.find_element(
    By.CSS_SELECTOR, ".button-group > button:nth-child(2)"
)
time.sleep(3)
show_confirm_btn.click()
confirm = wd.switch_to.alert
print(confirm.text)
time.sleep(3)
confirm.accept()
# confirm.dismiss()
time.sleep(5)
"""
# click prompt
show_prompt_btn = wd.find_element(
    By.CSS_SELECTOR, ".button-group > button:nth-child(3)"
)
time.sleep(3)
show_prompt_btn.click()
prompt = wd.switch_to.alert
print(prompt.text)
time.sleep(3)
# Chrome浏览器不会显示输入的内容
prompt.send_keys("Annie")
time.sleep(3)
prompt.accept()
time.sleep(55)
